package com.sinoglobal.ningxia.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.sinoglobal.ningxia.R;
import com.sinoglobal.ningxia.activity.mico.ProgramInfoActivity;
import com.sinoglobal.ningxia.adapter.NewVideoFramentAdapter;
import com.sinoglobal.ningxia.beans.ProgramaListBean;
import com.sinoglobal.ningxia.utils.FlyUtil;

import java.util.List;

/**
 * Created by XINDZ on 2017/2/13.
 * 功能:视频--栏目
 */

public class NewVideoFragment extends Fragment {
    private ProgramaListBean.ListBean listBean;
    private List<ProgramaListBean.ListBean.LanmuBean> lanmuBeanList;
    private NewVideoFramentAdapter newVideoFramentAdapter;
    private ListView listView;

    public static NewVideoFragment newInstance(ProgramaListBean.ListBean listBean) {
        NewVideoFragment newVideoFragment = new NewVideoFragment();
        newVideoFragment.listBean = listBean;
        return newVideoFragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.frag_newvideo, null);
        listView = (ListView) view.findViewById(R.id.lv_frag_newvideo);
        lanmuBeanList = listBean.getLanmu();
        newVideoFramentAdapter = new NewVideoFramentAdapter(getActivity(), lanmuBeanList);
        listView.setAdapter(newVideoFramentAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                ProgramaListBean.ListBean.LanmuBean lanmuBean = lanmuBeanList.get(i);
                Intent go = new Intent();
                go.putExtra(ProgramaListBean.class.getName(), lanmuBean);
                go.setClass(getActivity(), ProgramInfoActivity.class);
                FlyUtil.intentForwardNetWork(getContext(), go);
            }
        });
        return view;
    }
}
